Let AOTAutogradCache cache graphs with custom autograd.Functions - #2162
Open
anijain2305 wants to merge 1 commit into
Open
Let AOTAutogradCache cache graphs with custom autograd.Functions#2162anijain2305 wants to merge 1 commit into
anijain2305 wants to merge 1 commit into
Conversation
UMA's forward contains custom autograd.Functions. AOTAutogradCache refuses to cache any graph containing one unless torch._functorch.config.autograd_cache_allow_custom_autograd_functions is set, so today the largest graph misses the cache and is retraced and recompiled from scratch on every process start. Warm start ends up paying most of a cold compile. Turning it on halves warm compile time. On uma-s-1p2 with 1000 atoms, a second process run against caches populated by the first: autograd_cache_allow_custom_autograd_functions=False 22.6s autograd_cache_allow_custom_autograd_functions=True 10.2s which is a >2x reduction (3 runs each, 22.79/22.35/22.69 vs 10.86/9.92/9.76, measured as the union of top-level compile events from tlparse). Cold start is unaffected, 53.5s vs 54.0s, within run-to-run noise: the flag decides only whether the second run can reuse the first run's work. PyTorch intends to flip this flag to True by default, but that is waiting on thorough internal testing across models. Nothing about UMA needs to wait for it: the model's custom autograd.Functions are ordinary differentiable ops with no state that would make a cached graph unsafe to reuse, so we can opt in now and drop this line once the default changes. This change was authored with the assistance of an AI coding agent.
frostedoyster
self-requested a review
August 13, 2026 18:37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UMA's forward contains custom autograd.Functions. AOTAutogradCache refuses to cache any graph containing one unless
torch._functorch.config.autograd_cache_allow_custom_autograd_functions is set, so today the largest graph misses the cache and is retraced and recompiled from scratch on every process start. Warm start ends up paying most of a cold compile.
Turning it on halves warm compile time. On uma-s-1p2 with 1000 atoms, a second process run against caches populated by the first:
autograd_cache_allow_custom_autograd_functions=False 22.6s
autograd_cache_allow_custom_autograd_functions=True 10.2s
which is a >2x reduction (3 runs each, 22.79/22.35/22.69 vs 10.86/9.92/9.76, measured as the union of top-level compile events from tlparse). Cold start is unaffected, 53.5s vs 54.0s, within run-to-run noise: the flag decides only whether the second run can reuse the first run's work.
PyTorch intends to flip this flag to True by default, but that is waiting on thorough internal testing across models. Nothing about UMA needs to wait for it: the model's custom autograd.Functions are ordinary differentiable ops with no state that would make a cached graph unsafe to reuse, so we can opt in now and drop this line once the default changes.
This change was authored with the assistance of an AI coding agent.